<template>
    <div>
		<div class="times">
			<span :class="type == 1 ? 'check':''" @click="selectType(1)">时分</span>
			<span :class="type == 2 ? 'check':''" @click="selectType(2)">5分钟</span>
			<span :class="type == 3 ? 'check':''" @click="selectType(3)">15分钟</span>
			<span :class="type == 4 ? 'check':''" @click="selectType(4)">30分钟</span>
			<span :class="type == 5 ? 'check':''" @click="selectType(5)">日</span>
			<span :class="type == 6 ? 'check':''" @click="selectType(6)">周</span>
			<span :class="type == 7 ? 'check':''" @click="selectType(7)">月</span>
		</div>
        <div id="main" class="chart-box" style="height: 300px;width:90%; margin:0 auto;"></div>
        <!--<div class="chart-box" id="chart_box"></div>-->
    </div>
</template>

<script>
import * as echarts from 'echarts';
import { createChart } from 'lightweight-charts';
import {index_xiantiao_api} from "@/assets/js/api";

export default {
    name: "chart",
    data() {
        return {
            time_interval: "",
			myChart:'',
			candleSeries:'',
			type:1,
			ldata:[],
			data:{"code":"200","msg":"\u6210\u529f\uff01","data":[["2021-02-23",12.692675450000001,12.60422475,12.51577405,12.736900799999999,3119000],["2021-02-24",12.6484501,12.383098,12.1177459,12.78112615,3042200],["2021-02-25",12.383098,12.6484501,12.25042195,12.736900799999999,2435400],["2021-02-26",12.383098,12.6484501,12.294647300000001,12.692675450000001,1618800],["2021-03-01",12.8253515,13.134928949999999,12.6484501,13.134928949999999,4142000],["2021-03-02",13.267605,13.090703600000001,12.86957685,13.311830350000001,2266500],["2021-03-03",13.090703600000001,13.090703600000001,12.9138022,13.1791543,2083100],["2021-03-04",13.134928949999999,12.6484501,12.51577405,13.1791543,2662200],["2021-03-05",12.60422475,12.9138022,12.42732335,12.95802755,2998400],["2021-03-08",13.134928949999999,13.0022529,12.9138022,13.134928949999999,2432500],["2021-03-09",12.86957685,13.0022529,12.8253515,13.04647825,1715900],["2021-03-10",13.04647825,13.8867599,12.95802755,13.8867599,10008900],["2021-03-11",14.7712669,14.3290134,14.2405627,14.7712669,5383600],["2021-03-12",14.28478805,14.28478805,14.152111999999999,14.4174641,2779700],["2021-03-15",14.2405627,14.81549225,14.0636613,15.1250697,7205100],["2021-03-16",14.81549225,15.036619,14.5943655,15.3904218,4574600],["2021-03-17",15.036619,14.6828162,14.6828162,15.08084435,3564400],["2021-03-18",14.81549225,14.7712669,14.550140149999999,15.1250697,4294500],["2021-03-19",14.7712669,14.7712669,14.63859085,15.036619,2546400],["2021-03-22",14.7712669,14.7712669,14.5943655,14.903942950000001,2836500],["2021-03-23",14.7712669,14.46168945,14.2405627,14.81549225,3335400],["2021-03-24",14.0636613,13.8867599,13.75408385,14.37323875,3844300],["2021-03-25",13.8867599,14.0636613,13.66563315,14.0636613,2824100],["2021-03-26",14.019435949999998,14.107886650000001,13.1791543,14.152111999999999,3849300],["2021-03-29",14.152111999999999,14.37323875,14.019435949999998,14.505914800000001,4219700],["2021-03-30",14.4174641,14.550140149999999,14.3290134,14.7712669,3733700],["2021-03-31",14.505914800000001,14.6828162,14.4174641,14.7712669,2755000],["2021-04-01",14.5943655,14.72704155,14.550140149999999,14.7712669,2744300],["2021-04-02",14.81549225,14.72704155,14.550140149999999,14.948168299999999,3652000],["2021-04-05",14.7712669,14.63859085,14.505914800000001,14.8597176,2805900],["2021-04-06",14.550140149999999,14.505914800000001,14.3290134,14.63859085,2265400],["2021-04-07",14.3290134,14.5943655,14.19633735,14.5943655,2505300],["2021-04-08",14.63859085,14.8597176,14.63859085,14.948168299999999,5698900],["2021-04-09",14.948168299999999,15.4788725,14.948168299999999,15.6557739,7489300],["2021-04-12",15.5673232,15.4788725,15.346196449999999,15.8326753,3123700],["2021-04-13",15.4788725,15.036619,14.8597176,15.5673232,5387000],["2021-04-14",14.7712669,15.78844995,14.6828162,15.87690065,9230800],["2021-04-15",15.87690065,15.8326753,15.523097850000001,16.0980274,6317100],["2021-04-16",15.4788725,15.78844995,14.948168299999999,15.921126000000001,4901000],["2021-04-19",15.921126000000001,15.699999250000001,15.301971100000001,15.921126000000001,6182100],["2021-04-20",15.699999250000001,15.4788725,15.036619,15.87690065,5270500],["2021-04-22",15.1250697,14.4174641,14.4174641,15.301971100000001,4606100],["2021-04-23",14.505914800000001,14.81549225,13.7983092,14.81549225,6124300],["2021-04-26",14.81549225,14.152111999999999,14.019435949999998,14.8597176,2858500],["2021-04-27",13.9752106,14.7712669,13.9752106,15.1250697,8657700],["2021-04-28",14.7712669,14.7712669,14.6828162,15.301971100000001,5392100],["2021-04-29",14.7712669,14.550140149999999,14.505914800000001,14.99239365,2520300],["2021-05-04",13.9752106,14.152111999999999,13.9752106,14.3290134,3700900],["2021-05-05",14.19633735,14.4174641,14.107886650000001,14.72704155,5775000],["2021-05-06",14.46168945,14.019435949999998,14.019435949999998,14.505914800000001,4071900],["2021-05-07",13.930985249999999,13.57718245,13.532957099999999,14.107886650000001,4942500],["2021-05-10",13.267605,13.8867599,13.22337965,13.9752106,6036100],["2021-05-11",13.8867599,13.8867599,13.75408385,14.0636613,3403800],["2021-05-12",13.7983092,13.9752106,13.709858500000001,14.107886650000001,3960500],["2021-05-13",14.0636613,13.709858500000001,13.709858500000001,14.152111999999999,4031900],["2021-05-14",13.75408385,13.75408385,13.709858500000001,14.0636613,4288600],["2021-05-17",13.8867599,13.532957099999999,13.532957099999999,13.9752106,3141200],["2021-05-18",13.6214078,13.40028105,13.311830350000001,13.75408385,2345200],["2021-05-19",13.3560557,13.3560557,13.267605,13.66563315,3589700],["2021-05-20",13.40028105,13.134928949999999,13.04647825,13.532957099999999,2730500],["2021-05-21",13.134928949999999,13.532957099999999,13.0022529,13.709858500000001,4783500],["2021-05-24",13.6214078,13.7983092,13.6214078,14.019435949999998,6637300],["2021-05-25",13.9752106,13.930985249999999,13.84253455,14.19633735,3640500],["2021-05-26",13.7983092,13.709858500000001,13.57718245,14.019435949999998,3320600],["2021-05-27",13.6214078,13.40028105,13.267605,13.7983092,3740400],["2021-05-28",13.4445064,13.57718245,13.3560557,13.66563315,4608500],["2021-05-31",13.532957099999999,13.488731750000001,13.311830350000001,13.6214078,2402100],["2021-06-01",13.66563315,13.40028105,13.40028105,13.75408385,2266400],["2021-06-02",13.3560557,13.4445064,13.267605,13.488731750000001,2392000],["2021-06-03",13.57718245,14.37323875,13.57718245,14.37323875,9756000],["2021-06-04",14.5943655,14.4174641,14.28478805,14.7712669,5496500],["2021-06-07",14.550140149999999,14.152111999999999,13.9752106,14.63859085,2465700],["2021-06-08",14.0636613,13.66563315,13.6214078,14.28478805,5139900],["2021-06-09",13.66563315,13.709858500000001,13.3560557,13.84253455,4965400],["2021-06-10",13.709858500000001,13.8867599,13.57718245,13.9752106,3797400],["2021-06-11",13.9752106,14.2405627,13.9752106,14.4174641,4647900],["2021-06-14",14.3290134,14.28478805,14.0636613,14.505914800000001,4586000],["2021-06-15",14.0636613,15.25774575,14.019435949999998,15.25774575,20250800],["2021-06-16",15.744224599999999,15.8326753,15.25774575,16.05380205,15032000],["2021-06-17",15.78844995,16.93830905,15.744224599999999,16.93830905,24665400],["2021-06-18",16.805633,17.20366115,16.3633795,17.867041399999998,20342000],["2021-06-21",17.20366115,17.601689299999997,16.540280900000003,17.69014,18287300],["2021-06-22",17.73436535,17.2478865,16.8940837,17.867041399999998,21219400],["2021-06-23",17.20366115,16.805633,16.761407650000002,17.557463950000002,18722100],["2021-06-24",16.93830905,16.849858349999998,16.6287316,17.2478865,17237200],["2021-06-25",16.8940837,16.3633795,16.1864781,17.0709851,17157600],["2021-06-28",16.4518302,17.46901325,16.05380205,17.46901325,20292000],["2021-06-29",17.645914649999998,18.1323935,17.557463950000002,18.574647000000002,21458900],["2021-06-30",17.778590700000002,17.2478865,17.2478865,17.867041399999998,13771700],["2021-07-01",17.2478865,17.20366115,16.7171823,17.38056255,10794000],["2021-07-02",17.0709851,16.49605555,16.40760485,17.0709851,17217000],["2021-07-05",16.4518302,16.40760485,15.96535135,16.805633,7067000],["2021-07-06",16.40760485,15.301971100000001,15.301971100000001,16.8940837,5513600],["2021-07-07",15.1250697,15.301971100000001,14.63859085,15.4788725,8404400],["2021-07-08",15.3904218,14.7712669,14.6828162,15.43464715,6239800],["2021-07-09",14.4174641,14.2405627,14.2405627,14.948168299999999,7290600],["2021-07-12",14.0636613,13.6214078,13.267605,14.0636613,11423200],["2021-07-13",13.7983092,14.0636613,13.532957099999999,14.0636613,3904300],["2021-07-14",14.05,13.74,13.43,14.05,3234800],["2021-07-15",13.43,14.09,13.43,14.27,4526400],["2021-07-16",14.18,13.91,13.87,14.18,3757400],["2021-07-19",13.38,13.08,13.03,13.65,6257700],["2021-07-20",13.08,13.65,12.94,13.65,4679900],["2021-07-21",13.65,13.65,13.61,13.96,4420900],["2021-07-22",13.69,14.09,13.56,14.09,5711900],["2021-07-23",13.78,13.74,13.69,14.14,5198700],["2021-07-26",13.52,13.65,13.43,13.83,2389000],["2021-07-27",13.78,14.14,13.78,14.31,9434500],["2021-07-28",14.14,14.4,14,14.58,5672200],["2021-07-29",14.44,14.27,14.18,14.58,3761500],["2021-07-30",14.36,14.27,14.18,14.4,3698100],["2021-08-02",14.27,14.36,14.22,14.75,7494200],["2021-08-03",14.4,14.36,14.18,14.49,5279000],["2021-08-04",14.4,14.31,14.27,14.49,4854100],["2021-08-05",14.27,14.53,14.22,14.62,5101200],["2021-08-06",14.58,15.06,14.53,15.42,13579700],["2021-08-09",15.06,15.24,15.02,15.46,6421100],["2021-08-10",15.46,15.33,15.15,15.55,6427400],["2021-08-11",15.37,15.02,14.93,15.64,9216300],["2021-08-12",15.02,15.24,14.84,15.55,6672400],["2021-08-13",15.24,15.33,14.93,15.42,5414500],["2021-08-16",15.51,15.9,15.46,16.12,11298700],["2021-08-17",15.9,15.64,15.55,15.99,5942300],["2021-08-18",15.68,15.59,15.51,15.77,4536300],["2021-08-19",15.77,16.12,15.55,16.21,9916600],["2021-08-20",16.26,15.37,15.02,16.3,13527400],["2021-08-23",15.37,14.84,14.71,15.37,7679200],["2021-08-24",14.8,14.84,14.62,15.02,5542600],["2021-08-25",14.84,15.11,14.62,15.11,3931900],["2021-08-26",15.2,15.15,14.93,15.28,3933700],["2021-08-27",17.1,17.85,16.75,17.85,9418600],["2021-08-30",18.05,17.7,17.7,18.1,7540200],["2021-08-31",17.7,17.75,17.5,18.2,10536500],["2021-09-01",16,16.2,16,16.4,10066400],["2021-09-06",16.5,16.65,16.45,16.9,9503800],["2021-09-07",16.6,16,16,16.65,9332100],["2021-09-08",16,15.9,15.75,16.1,5395800],["2021-09-09",15.95,16.15,15.9,16.3,3252000],["2021-09-10",16.15,16.3,16,16.4,5578100],["2021-09-13",16.45,16.05,15.95,16.45,3564300],["2021-09-14",16.05,15.8,15.8,16.4,3737700],["2021-09-15",15.8,16.1,15.6,16.15,3612000],["2021-09-16",16.15,16,15.95,16.2,3054200],["2021-09-17",16,16.55,15.9,16.8,11029700],["2021-09-20",16.6,16.2,16.15,16.65,4587200],["2021-09-21",16,16.05,15.8,16.2,5319000],["2021-09-22",16.1,16.5,16,16.6,6425400],["2021-09-23",16.7,16.6,16.5,17.2,9738200],["2021-09-24",16.6,16.3,16.25,16.6,3364500],["2021-09-27",16.25,15.55,15.55,16.35,8969600],["2021-09-28",15.6,15.75,15.3,15.75,6738400],["2021-09-29",15.7,15.7,15.45,15.75,3324600],["2021-09-30",15.7,15.7,15.65,15.9,2616300],["2021-10-01",15.7,15.55,15.5,15.9,4389500],["2021-10-04",15.55,15.7,15.5,15.75,2980400],["2021-10-05",15.8,16,15.75,16.25,4878200],["2021-10-06",16.25,16.1,16,16.25,3996500],["2021-10-07",16.05,16.55,15.95,16.6,9589600],["2021-10-08",16.5,16.2,16.2,16.5,2910700],["2021-10-11",16.2,16.2,16.1,16.35,3755700],["2021-10-12",16.1,16.25,16.05,16.3,5740900],["2021-10-13",16.25,16.25,16.15,16.45,3570900],["2021-10-14",16.3,16.55,16.25,16.8,10532000],["2021-10-15",16.6,16.35,16.3,16.7,5276900],["2021-10-18",16.35,16.15,16.1,16.45,4792000],["2021-10-19",16.15,16.1,16.05,16.3,4283200],["2021-10-20",16.1,16,15.75,16.25,5431100],["2021-10-21",16,15.9,15.8,16.05,4488900],["2021-10-22",15.95,16.15,15.9,16.3,4055900],["2021-10-25",16.2,16.15,16.1,16.45,5513200],["2021-10-26",16.2,16.2,15.95,16.2,3588500],["2021-10-27",16.45,17.1,16.25,17.2,18813200],["2021-10-28",17.25,16.9,16.9,17.25,7035200],["2021-10-29",16.95,17.2,16.9,17.45,8258600],["2021-11-01",17.2,17.55,16.95,17.85,13662600],["2021-11-02",17.4,17.5,17.4,17.9,7492300],["2021-11-03",17.7,16.7,16.65,17.7,13100200],["2021-11-04",16.7,16.6,16.5,16.9,5645900],["2021-11-05",16.7,17,16.65,17.25,6214100],["2021-11-08",17.3,17.25,17,17.5,6970500],["2021-11-09",17.3,17.1,17.05,17.5,8201100],["2021-11-10",17.2,18.15,17,18.25,16572600],["2021-11-11",18.2,18,17.7,18.35,9821700],["2021-11-12",18,18.3,17.9,18.7,8413900],["2021-11-15",18.3,18.4,18,19.1,10735500],["2021-11-16",18.2,17.8,17.7,18.45,9594700],["2021-11-17",17.85,17.9,17.75,18.2,6020300],["2021-11-18",18,18.6,17.9,18.8,9065600],["2021-11-19",18.55,17.5,17.3,18.9,12341000],["2021-11-22",17.55,16.6,16.6,17.75,8562500],["2021-11-23",16.6,17.1,16.5,17.2,4224800],["2021-11-24",17.3,17,16.85,17.35,6844400],["2021-11-25",17,17.1,16.9,17.45,4322600],["2021-11-26",17.2,16.9,16.8,17.25,5054800],["2021-11-29",16.4,16.8,16.4,16.95,5164400],["2021-11-30",17.1,16.85,16.75,17.45,6030000],["2021-12-01",16.85,17.4,16.85,17.5,5479000],["2021-12-02",17.4,17.55,17.4,17.95,6386300],["2021-12-03",17.55,16.9,16.9,17.65,5144600],["2021-12-06",16.9,16.25,15.95,17.05,7035200],["2021-12-07",16.4,16.55,16.3,16.7,3526300],["2021-12-08",16.75,16.6,16.55,17,3454600],["2021-12-09",16.55,16.8,16.55,17,2235200],["2021-12-10",16.8,17,16.75,17.15,3543500],["2021-12-13",17.3,17.65,17.1,17.8,8393100],["2021-12-14",17.75,18.35,17.4,18.5,10845800],["2021-12-15",18.4,18.5,18.4,19.3,12036100],["2021-12-16",18.4,18.7,18.1,19.2,9366900],["2021-12-17",18.75,18.6,18.5,19.2,6935400],["2021-12-20",18.5,18.1,17.9,18.7,7088500],["2021-12-21",18,19.35,17.6,19.35,15444900],["2021-12-22",20,20,19.7,20.6,11386100],["2021-12-23",20,21.4,19.5,21.4,18312800],["2021-12-24",21.5,21.35,20.95,22.2,10541100],["2021-12-27",21.35,21.9,21.05,22.25,8671300],["2021-12-28",22,21.3,21.1,22.25,10859700],["2021-12-29",21.3,21.55,21.05,21.8,7501300],["2021-12-30",21.7,21,21,21.85,5194100],["2021-12-31",21,20.2,20,21.25,10379500],["2022-01-04",20.1,20.7,20.1,21.4,7354500],["2022-01-05",20.8,20.95,20.65,21.8,7187400],["2022-01-06",20.9,22.4,20.8,22.4,12375600],["2022-01-07",22.95,22.8,22.55,23.15,7009900],["2022-01-10",23,21.9,21.8,23.4,8842600],["2022-01-11",21.3,20,20,21.75,13383600],["2022-01-12",19.8,19.6,18.6,20.5,12757700],["2022-01-13",19.6,18.25,18.25,20.2,7501100],["2022-01-14",17.85,18.35,17.7,19,7069100],["2022-01-17",18.45,17.1,17.1,18.7,10039900],["2022-01-18",16.9,17.6,16.9,17.9,5835200],["2022-01-19",17.8,17.6,17.2,18.1,3173800],["2022-01-20",17.65,18.05,17.45,18.35,4607700],["2022-01-21",18,17.75,17.75,18.15,4433200],["2022-01-24",17.55,16.55,16.55,17.65,7863000],["2022-01-25",16.4,17,16.1,17.05,4383700],["2022-01-26",17.1,16.55,16.55,17.3,3096900],["2022-01-27",16.55,16.6,16.5,16.9,2972100],["2022-01-28",16.8,16.5,16.4,16.8,3178100],["2022-02-07",17,17.35,16.7,17.4,4002100],["2022-02-08",17.45,17.4,17.1,17.75,3086200],["2022-02-09",17.5,17.75,17.3,17.8,3788100],["2022-02-10",17.9,17.8,17.7,18.15,5336500],["2022-02-11",17.9,17.9,17.6,18.1,3413200],["2022-02-14",17.5,17.35,17.3,17.9,4556700],["2022-02-15",17.4,17.4,17.25,17.6,2987100],["2022-02-16",17.75,18,17.55,18.25,4148000],["2022-02-17",18,18.05,17.95,18.35,4481600],["2022-02-18",17.9,18.1,17.8,18.35,3703100],["2022-02-21",18.15,18.65,18.05,18.85,6603500],["2022-02-22",18.3,18.05,17.75,18.4,6484000],["2022-02-23",18.05,18.15,18.05,18.35,3252300],["2022-02-24",18.1,17.55,17.1,18.2,8530200],["2022-02-25",17.85,17.8,17.7,18.1,3916600],["2022-02-28",17.9,17.65,17.55,17.9,3552800],["2022-03-01",17.6,18,17.55,18.3,5617200],["2022-03-02",18.05,17.65,17.5,18.05,4857200],["2022-03-03",17.8,18.5,17.65,18.5,11340700],["2022-03-04",18.6,18.4,18.3,18.75,4733200],["2022-03-07",18.1,18.05,17.85,18.3,8793300],["2022-03-08",17.85,17.7,17.7,18.35,5894000],["2022-03-09",17.8,17.55,17.35,17.95,5467600],["2022-03-10",17.85,17.7,17.7,18,3608600],["2022-03-11",17.6,17.8,17.6,18.1,4695400],["2022-03-14",17.75,17.2,17.05,17.75,4716100],["2022-03-15",17.25,17.35,17.15,17.45,2728500],["2022-03-16",17.5,17.7,17.35,18.1,3356900],["2022-03-17",18,17.65,17.6,18,2485600],["2022-03-18",17.65,17.6,17.55,17.9,2588700],["2022-03-21",17.65,17.8,17.5,17.9,4225100],["2022-03-22",17.9,17.8,17.7,17.9,4361400],["2022-03-23",17.8,18.1,17.75,18.3,8173000],["2022-03-24",18.1,19.35,18,19.35,19729800],["2022-03-25",19.5,19.1,19,19.9,10262600],["2022-03-28",18.8,19,18.7,19.4,8408100],["2022-03-29",19,19.4,18.9,19.9,9892400],["2022-03-30",19.2,18.6,18.5,19.7,9806100],["2022-03-31",18.75,18.7,18.55,19.2,5252700],["2022-04-01",18.8,19.1,18.6,19.25,4983000],["2022-04-04",19.4,18.75,18.75,19.4,6676700],["2022-04-05",18.75,18.7,18.6,19,5017000],["2022-04-06",18.55,18.35,18.1,18.85,6529500],["2022-04-07",18.2,17.5,17.5,18.5,9718900],["2022-04-08",17.7,17.5,17.5,17.9,4876600],["2022-04-12",17.55,16.65,16.65,17.8,5456300],["2022-04-13",16.7,17.3,16.7,17.3,3694500],["2022-04-14",17.5,17.2,17.1,17.6,2398600],["2022-04-15",17.2,16.9,16.75,17.3,2998800],["2022-04-18",16.8,15.85,15.75,16.8,7605800],["2022-04-19",16.15,14.75,14.75,16.15,5076500],["2022-04-20",14.8,14.3,14.1,15,4639800],["2022-04-21",13.8,13.7,13.3,14.45,6516700],["2022-04-22",13.9,13.8,13.4,14.45,4300300],["2022-04-25",13.95,12.85,12.85,14.15,5592900],["2022-04-26",12.35,13.3,12.2,13.3,4855700],["2022-04-27",13.25,13.5,13,13.65,3281500],["2022-04-28",13.65,13.55,13.5,13.9,2725800],["2022-04-29",13.5,14.05,13.35,14.05,4682400],["2022-05-04",14.1,13.8,13.7,14.15,2457800],["2022-05-05",14,13.4,13.35,14,3222400],["2022-05-06",13.1,12.85,12.85,13.35,3714600],["2022-05-09",12.6,12,12,12.8,5787100],["2022-05-10",11.45,12.2,11.3,12.2,4334400],["2022-05-11",12.2,12.4,12.2,12.5,2619900],["2022-05-12",12.25,11.55,11.55,12.35,3658800],["2022-05-13",11.55,10.75,10.75,11.75,7024900],["2022-05-16",11.15,10.8,10.8,11.35,3760000],["2022-05-17",11,11.55,10.85,11.55,4081900],["2022-05-18",11.9,11.8,11.7,12.15,4201000],["2022-05-19",11.4,11.8,11.4,12.1,4539400],["2022-05-20",12,12.1,11.8,12.2,4043500],["2022-05-23",12.3,11.9,11.7,12.3,3208500],["2022-05-24",11.9,12,11.35,12,4355900],["2022-05-25",12.1,12.6,11.85,12.8,5726300],["2022-05-26",12.75,12.75,12.6,13.1,5287400],["2022-05-27",12.7,12.65,12.6,12.85,3347600],["2022-05-30",12.7,12.75,12.6,12.85,3600300],["2022-05-31",12.7,12.6,12.4,12.75,3555500],["2022-06-01",12.65,12.5,12.4,12.7,2610500],["2022-06-02",12.55,12.45,12.35,12.8,2983500],["2022-06-03",12.5,12.45,12.1,12.7,3603100],["2022-06-06",12.45,12.25,12.2,12.55,2444100],["2022-06-07",12.1,12.05,11.6,12.2,4347900],["2022-06-08",12.15,12.45,12.1,12.6,4068800]]},
        }
    },
    props: {
        symbol: {
            type: String,
        }
    },
    
    methods: {
		
		selectType(type){
			
			this.type = type;
			
			var num = 0;
			
			switch(type){
				case 1:
					this.drawAreaLine(this.splitData(this.ldata.data));
					break;
				case 2:
					this.fnGetDemoChart(this.calculateMA(5,this.ldata.data));
					break;
				case 3:
					this.fnGetDemoChart(this.calculateMA(15,this.ldata.data));
					break;
				case 4:
					this.fnGetDemoChart(this.calculateMA(30,this.ldata.data));
					break;
				case 5:
					this.fnGetDemoChart(this.data.data);
					break;
				case 6:

					this.fnGetDemoChart(this.calculateMA(7,this.splitData(this.data.data)));
					break;
				case 7:
					this.fnGetDemoChart(this.calculateMA(30,this.splitData(this.data.data)));
					break;
			}
			
			
		},
        
        fnGetChart() {
            /* index_xiantiao_api({
                symbol: this.symbol,
            }).then(res => {
                if (res.code == 200) {
                    this.fnGetDemoChart(res.data);
                }
            }) */
			//this.fnGetDemoChart(this.data.data);
			this.fnGetDemoChart(this.data.data);
        },
        
        splitData(rawData) {
            let categoryData = [];
            let values = [];
            let volumes = [];
            for (let i = 0; i < rawData.length; i++) {
                categoryData.push(rawData[i].splice(0, 1)[0]);
                values.push(rawData[i]);
                volumes.push([i, rawData[i][4], rawData[i][0] > rawData[i][1] ? 1 : -1]);
            }
            return {
                categoryData: categoryData,
                values: values,
                volumes: volumes
            };
        },
        calculateMA(dayCount, data) {
            var result = [];
            for (var i = 0, len = data.values.length; i < len; i++) {
                if (i < dayCount) {
                    result.push('-');
                    continue;
                }
                var sum = 0;
                for (var j = 0; j < dayCount; j++) {
                    sum += data.values[i - j][1];
                }
                result.push(+(sum / dayCount).toFixed(3));
            }
            return result;
        },
        
        fnGetDemoChart(resData) {
            
			//var data = this.splitData(resData);
			
			var data = this.generateBarsData();
			console.log(data);
			this.candleSeries.setData(data);
			
			var timeScale = this.myChart.timeScale();
        },
		
		getBusinessDayBeforeCurrentAt(date, daysDelta) {
			const dateWithDelta = new Date(Date.UTC(date.year, date.month - 1, date.day - daysDelta, 0, 0, 0, 0));
			return { year: dateWithDelta.getFullYear(), month: dateWithDelta.getMonth() + 1, day: dateWithDelta.getDate() };
		},
		
		generateBarsData(period) {
			var res = [];
			var controlPoints = this.generateControlPoints(res, period);
			for (var i = 0; i < controlPoints.length - 1; i++) {
				var left = controlPoints[i];
				var right = controlPoints[i + 1];
				this.fillBarsSegment(left, right, res);
			}
			return res;
		},
		
		fillBarsSegment(left, right, points) {
			var deltaY = right.price - left.price;
			var deltaX = right.index - left.index;
			var angle = deltaY / deltaX;
			for (var i = left.index; i <= right.index; i++) {
				var basePrice = left.price + (i - left.index) * angle;
				var openNoise = (0.1 - Math.random() * 0.2) + 1;
				var closeNoise = (0.1 - Math.random() * 0.2) + 1;
				var open = basePrice * openNoise;
				var close = basePrice * closeNoise;
				var high = Math.max(basePrice * (1 + Math.random() * 0.2), open, close);
				var low = Math.min(basePrice * (1 - Math.random() * 0.2), open, close);
				points[i].open = open;
				points[i].high = high;
				points[i].low = low;
				points[i].close = close;
			}
		},
		
		generateControlPoints(res, period, dataMultiplier) {
			var time = period !== undefined ? period.timeFrom : { day: 1, month: 1, year: 2018 };
			var timeTo = period !== undefined ? period.timeTo : { day: 1, month: 1, year: 2019 };
			var days = this.getDiffDays(time, timeTo);
			dataMultiplier = dataMultiplier || 1;
			var controlPoints = [];
			controlPoints.push({ index: 0, price: this.getRandomPrice() * dataMultiplier });
			for (var i = 0; i < days; i++) {
				if (i > 0 && i < days - 1 && Math.random() < 0.05) {
					controlPoints.push({ index: i, price: this.getRandomPrice() * dataMultiplier });
				}
				res.push({ time: time });
				time = this.nextBusinessDay(time);
			}
			controlPoints.push({ index: res.length - 1, price: this.getRandomPrice() * dataMultiplier });
			return controlPoints;
		},
		
		getDiffDays(dateFrom, dateTo) {
			var df = this.convertBusinessDayToUTCTimestamp(dateFrom);
			var dt = this.convertBusinessDayToUTCTimestamp(dateTo);
			var diffTime = Math.abs(dt.getTime() - df.getTime());
			return Math.ceil(diffTime / (1000 * 60 * 60 * 24));
		},
		
		convertBusinessDayToUTCTimestamp(date) {
			return new Date(Date.UTC(date.year, date.month - 1, date.day, 0, 0, 0, 0));
		},
		
		nextBusinessDay(time) {
			var d = this.convertBusinessDayToUTCTimestamp({ year: time.year, month: time.month, day: time.day + 1 });
			return { year: d.getUTCFullYear(), month: d.getUTCMonth() + 1, day: d.getUTCDate() };
		},
		
		getRandomPrice() {
			return 10 + Math.round(Math.random() * 10000) / 100;
		}
    },
    
    mounted() {
		
		var chartDom = document.getElementById('main');
		this.myChart = createChart(chartDom);
		
		this.candleSeries = this.myChart.addCandlestickSeries();
		
        this.fnGetChart();
        
        /* window.onresize = () => {
            this.fnGetChart();
        }; */
        
        // this.time_interval = setInterval(()=>{
        //     // console.log("fnGetIndex");
        //     this.fnGetDemoChart();
        // },5000)
    },
    destroyed() {
        clearInterval(this.time_interval);
    },
    
}
</script>
<style lang="scss" scoped>
	.times{
		width: 90%;
		margin: 0 auto;
		margin-bottom: 10px;
		span{
			padding-left: 10px;
			font-size: 12px;
		}
		span.check{
			color: #ef5963;
		}
	}
	
</style>

<!--https://echarts.apache.org/examples/zh/editor.html?c=candlestick-sh-->
